#!/bin/sh
#javaiftest - To be run from command line, to see results.
echo -e "\nEnvironment:"
echo -e "JAVA_HOME=$JAVA_HOME\nJRE_HOME=$JRE_HOME"
echo -e "\nwhich java:"
which java 2>/dev/null
echo -e "\njava -version:"
java -version
JAVARC=$?
grep -E '^JAVAHOME=|^JREHOME=|^JAVAVERSION=' /etc/javaif.conf > /tmp/javaifconf
echo ''
cat /tmp/javaifconf
. /tmp/javaifconf
[ $JAVARC -ne 0 ] && echo "Java is not installed." && exit

if [ "$JREHOME" != "$JAVAHOME" ] && echo "$JREHOME" | grep -q '/jre$' /etc/javaif.conf; then #JDK installed
 echo '/**
 * The HelloWorldApp class implements an application that
 * simply prints "Hello World!" to standard output.
 */
class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!"); // Display the string.
    }
}' > /tmp/HelloWorldApp.java
 cd /tmp
 echo -e "\njavac -verbose HelloWorldApp.java:"
 javac HelloWorldApp.java
else
 cd /usr/lib/javaif
fi
echo -e "\njava HelloWorldApp (expect Hello World!):"
java HelloWorldApp
